package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.MessageHistory;
import cn.wolfcode.crm.mapper.MessageHistoryMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IMessageHistoryService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageHistoryServiceImpl implements IMessageHistoryService {

    @Autowired
    private MessageHistoryMapper mapper;

    public void save(MessageHistory entity) {
        mapper.insert(entity);
    }

    public List<MessageHistory> list() {
        return mapper.selectAll();
    }

    public MessageHistory get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public PageResult query(QueryObject qo) {

        //1:查总条数
        int total = mapper.queryForCount(qo);

        if(total == 0){
            return new PageResult();
        }
        //2:查分页数据
        List<MessageHistory> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }

}
